﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="vendor/jquery/jquery.min.js"></script>
    <script>
        String.prototype.endWith = function (endStr) {
            var d = this.length - endStr.length;
            return (d >= 0 && this.lastIndexOf(endStr) == d)
        }
        var params = [];
        //获取url参数
        getUrlVars = function () {
            var vars = {};
            var hash;
            var hashs = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashs.length; i++) {
                hash = hashs[i].split('=');
                vars[hash[0]] = hash[1];
            }
            return vars;
        }

        window.onload = function () {
            //获取URL参数
            params = getUrlVars();
            var paramString = JSON.stringify(params);
            $.ajax({
                url: "Organization/GetCurrentUser?" + new Date().getTime(),
                type: "GET",
                dataType: "JSON",
                cache: false,
                async: false,
                params: {
                    random: new Date().getTime()
                },
                success: function (result, header, config, status) {
                    // console.log(result, 'result')
                    if (!result.Success) {
                        //alert(window.location.href)
                        window.top.location.href = "/Portal/#/platform/login";
                    } else {
                        $.ajax({
                            type: "POST",
                            async: false,
                            url: "InstanceSheets/InstanceSheets",
                            data: {paramString: paramString},
                            dataType: "json",
                            success: function (data) {
                                //只有一个表单直接跳转打开
                                if (data.Success && data.Extend == "Redirect") {
                                    window.localStorage.setItem("divContent", data.divContent);
                                    window.localStorage.setItem("postURL", data.postURL);
                                    window.location.href = data.Message;
                                } else if (data.Success) {
                                    //多个表单在界面上呈现连接选择打开
                                    var Urls = data.Extend;
                                    $(".panel-heading").show();
                                    var body = $("div[class='panel-body']");
                                    for (var i = 0; i < Urls.length; i++) {
                                        var div =
                                            "<div>" +
                                            "<span>表单：</span>" +
                                            "<a target='_self' href='" + Urls[i].Url + "'>" + Urls[i].Text + "</a>" +
                                            "</div>";
                                        body.append($(div));
                                    }
                                }
                            }
                        });
                    }
                },
                error: function (a, b, c) {
                    //$state.go("platform.login");
                    // alert("error");
                    window.top.location.href = "/Portal/#/platform/login"
                }
            });
        }

    </script>
</head>
<body>
<div class="container">
    <div class="panel">
        <div class="panel-heading" style="display:none;">
            <span>请选择表单:</span>
        </div>
        <div class="panel-body">

        </div>
    </div>
</div>
</body>
</html>
